import time

import requests
import pprint
import os
if not os.path.exists('视频文件夹'):
    os.makedirs('视频文件夹')

url = 'https://www.ku6.com/video/feed?'


def downWritefile(aduio_url,title,index):
    path=index    #把这个路径改成你自己的
    with open(path+title+r'.mp4',"wb") as fd:
        response=requstTools(aduio_url)   #请求并下载
        response.encoding = 'utf-8'
        fd.write(response.content)
        print('\n ：%s.mp4 下载成功!' %(title))

def requstTools(url):
    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.70'
    }
    response = requests.get(url, headers=headers)
    return response

import ffmpeg


def remove_watermark(video_path, output_path):
    input_stream = ffmpeg.input(video_path)
    output_stream = ffmpeg.output(input_stream, output_path, vcodec='copy', acodec='copy', **{'map_metadata': '-1', 'map_chapters': '-1'})
    ffmpeg.run(output_stream)

def get_params(page):

    params = {
        'pageNo': page,
        'pageSize': '40',
        'subjectId': '76'
    }

    return params

def claw_gaoxiao():

    for i in range(0, 10):
        params = get_params(i)
        print('--------第{}页正在下载'.format(i))

    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'
    }

    response = requests.get(url, headers=headers, params=params).json()
    print(response)
    list_data = response['data']
    print(list_data)

    for data in list_data:
    # pprint.pprint(data)

        data_mp4 = data['playUrl']

        data_name = data['title']
        cc = '视频名字：', data_name, '视频地址：', data_mp4
        print('视频名字：', data_name, '视频地址：', data_mp4)
        # with open('D:/var/20240704/out/'+'视频数据.txt', mode='a', encoding='utf-8')as f:
        #     f.write(str(cc))
        index = 'D:/var/20240704/out/'
        downWritefile(data_mp4,data_name,index)
        time.sleep(1)

if __name__ == '__main__':
    remove_watermark('D:/var/20240704/tmp/1.mp4', 'D:/var/20240704/tmp/2.mp4')